//
//  PlayerRecord.m
//  iMine
//
//  Created by gaoxiang on 09-3-30.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PlayerRecord.h"

#define PLAYERRECORD_NAME_BEGINNER	@"BeginnerName"
#define PLAYERRECORD_SCORE_BEGINNER	@"BeginnerSore"

#define PLAYERRECORD_NAME_NOVICE	@"NoviceName"
#define PLAYERRECORD_SCORE_NOVICE	@"NoviceScore"

#define PLAYERRECORD_NAME_EXPERT	@"ExpertName"
#define PLAYERRECORD_SCORE_EXPERT	@"ExpertScore"

static PlayerRecord *_instance;

@implementation PlayerRecord

+ (PlayerRecord *)instance
{
	if (!_instance) {
        _instance = [[PlayerRecord alloc] init];
		[[PlayerRecord instance] playerNameForBeginner];
		[[PlayerRecord instance] playerNameForNovice];
		[[PlayerRecord instance] playerNameForExpert];
    }
    return _instance;
}

- (void) dealloc {
    [super dealloc];
}

- (NSString *)playerNameForBeginner
{
	NSString *playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_BEGINNER];
	if (!playername)
	{
		[self setScoreForBeginner:@"Nobody" withScore:999];
		playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_BEGINNER];
	}
	return playername;
}
- (int)playerScoreForBeginner
{
	NSInteger integer = [[NSUserDefaults standardUserDefaults] integerForKey:PLAYERRECORD_SCORE_BEGINNER];
	return integer;
}
- (void)setScoreForBeginner:(NSString *)beginnerName withScore:(int)score
{
	[[NSUserDefaults standardUserDefaults] setObject:beginnerName forKey:PLAYERRECORD_NAME_BEGINNER];
	[[NSUserDefaults standardUserDefaults] setInteger:score forKey:PLAYERRECORD_SCORE_BEGINNER];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)playerNameForNovice
{
	NSString *playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_NOVICE];
	if (!playername)
	{
		[self setScoreForNovice:@"Nobody" withScore:999];
		playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_NOVICE];
	}
	return playername;
}
- (int)playerScoreForNovice
{
	NSInteger integer = [[NSUserDefaults standardUserDefaults] integerForKey:PLAYERRECORD_SCORE_NOVICE];
	return integer;
}
- (void)setScoreForNovice:(NSString *)noviceName withScore:(int)score
{
	[[NSUserDefaults standardUserDefaults] setObject:noviceName forKey:PLAYERRECORD_NAME_NOVICE];
	[[NSUserDefaults standardUserDefaults] setInteger:score forKey:PLAYERRECORD_SCORE_NOVICE];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)playerNameForExpert
{
	NSString *playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_EXPERT];
	if (!playername)
	{
		[self setScoreForExpert:@"Nobody" withScore:999];
		playername = [[NSUserDefaults standardUserDefaults] stringForKey:PLAYERRECORD_NAME_EXPERT];
	}
	return playername;
}
- (int)playerScoreForExpert
{
	NSInteger integer = [[NSUserDefaults standardUserDefaults] integerForKey:PLAYERRECORD_SCORE_EXPERT];
	return integer;
}
- (void)setScoreForExpert:(NSString *)expertName withScore:(int)score
{
	[[NSUserDefaults standardUserDefaults] setObject:expertName forKey:PLAYERRECORD_NAME_EXPERT];
	[[NSUserDefaults standardUserDefaults] setInteger:score forKey:PLAYERRECORD_SCORE_EXPERT];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

@end
